/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.economy.web.form.debt;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import org.apache.struts.action.ActionForm;
import org.apache.struts.util.LabelValueBean;

import ar.uba.fi.posgrado.common.model.Student;
import ar.uba.fi.posgrado.economy.model.CustomerAccount;
import ar.uba.fi.posgrado.economy.model.Benefit;
import ar.uba.fi.posgrado.economy.model.Debt;
import ar.uba.fi.posgrado.economy.model.DebtStatus;
import ar.uba.fi.posgrado.economy.model.Discount;

/**
 * Form para {@link Debt}
 * 
 * @author nicolas.gonzalez
 */
@SuppressWarnings("serial")
public class DebtForm extends ActionForm {

    private Long id;
    
    private String validityFrom;
    private String expiry;
    private Double balance;
    private Double originalBalance;
    
    private Long debtTypeId;
    private Long studentId;
    private Long accountId;
    private Long customerId;
    // Usado para AutoComplete
    private String corporateName;
    
    private DebtStatus debtStatus = DebtStatus.Active; // Cancelled, Paid, Balanced, Active
    private String debtStatusStr;
    
    private List<Student> students = new ArrayList<Student>();
    private List<CustomerAccount> accounts = new ArrayList<CustomerAccount>();
    
    private List<Benefit> availableBenefits = new ArrayList<Benefit>();
    private List<Discount> availableDiscounts = new ArrayList<Discount>();
    
    /* Strings separados por ';' con los ids de beneficios y descuentos asociados
     * la deuda. Es lo q fue seleccionando
     */ 
    private String selectedBenefits;
    private String selectedDiscounts;
    
    private List<Debt> debts = new ArrayList<Debt>();
    
    // Cantidad de deudas a crear. Por defecto se crea una sola
    private Integer amountToCreate = new Integer(1);
    // Apellido de lo q va ingresando para AutoComplete
    private String studentSurname;
    // 
    
    private String discountValues;
    private String discountPerc;
    private String benefitValues;
    private String benefitPerc;
    
    // Id del tipo de deuda seleccionado
    private String debtTypeSelected;
    private List<LabelValueBean> debtTypeOptions = new ArrayList<LabelValueBean>();
    
    private String debtStatusSelected;
    private List<LabelValueBean> debtStatusOptions = new ArrayList<LabelValueBean>(); 
    
    private String courseSelected;
    private List<LabelValueBean> courseOptions = new ArrayList<LabelValueBean>();
    
    // Si esta en true entonces filtra. Si no no
    private Boolean filterStudents = false;
    private String reason;
    
    public List<Long> getSelectedBenefitsIds() {
        List<Long> response = new ArrayList<Long>();
        StringTokenizer tokenizer = new StringTokenizer(this.selectedBenefits, ";");
        
        while (tokenizer.hasMoreElements()) {
            String idAsStr = (String) tokenizer.nextElement();
            
            response.add(new Long(idAsStr));
        }
        
        return response;
    }

    public List<Long> getSelectedDiscountsIds() {
        List<Long> response = new ArrayList<Long>();
        StringTokenizer tokenizer = new StringTokenizer(this.selectedDiscounts, ";");
        
        while (tokenizer.hasMoreElements()) {
            String idAsStr = (String) tokenizer.nextElement();
            
            response.add(new Long(idAsStr));
        }
        
        return response;
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the validityFrom
     */
    public String getValidityFrom() {
        return this.validityFrom;
    }

    /**
     * @param validityFrom the validityFrom to set
     */
    public void setValidityFrom(String validityFrom) {
        this.validityFrom = validityFrom;
    }

    /**
     * @return the expiry
     */
    public String getExpiry() {
        return this.expiry;
    }

    /**
     * @param expiry the expiry to set
     */
    public void setExpiry(String expiry) {
        this.expiry = expiry;
    }

    /**
     * @return the balance
     */
    public Double getBalance() {
        return this.balance;
    }

    /**
     * @param balance the balance to set
     */
    public void setBalance(Double balance) {
        this.balance = balance;
    }

    /**
     * @return the originalBalance
     */
    public Double getOriginalBalance() {
        return this.originalBalance;
    }

    /**
     * @param originalBalance the originalBalance to set
     */
    public void setOriginalBalance(Double originalBalance) {
        this.originalBalance = originalBalance;
    }

    /**
     * @return the debtTypeId
     */
    public Long getDebtTypeId() {
        return this.debtTypeId;
    }

    /**
     * @param debtTypeId the debtTypeId to set
     */
    public void setDebtTypeId(Long debtTypeId) {
        this.debtTypeId = debtTypeId;
    }

    /**
     * @return the studentId
     */
    public Long getStudentId() {
        return this.studentId;
    }

    /**
     * @param studentId the studentId to set
     */
    public void setStudentId(Long studentId) {
        this.studentId = studentId;
    }

    /**
     * @return the accountId
     */
    public Long getAccountId() {
        return this.accountId;
    }

    /**
     * @param accountId the accountId to set
     */
    public void setAccountId(Long accountId) {
        this.accountId = accountId;
    }

    /**
     * @return the debtStatus
     */
    public DebtStatus getDebtStatus() {
        return this.debtStatus;
    }

    /**
     * @param debtStatus the debtStatus to set
     */
    public void setDebtStatus(DebtStatus debtStatus) {
        this.debtStatus = debtStatus;
    }

    /**
     * @return the students
     */
    public List<Student> getStudents() {
        return this.students;
    }

    /**
     * @param students the students to set
     */
    public void setStudents(List<Student> students) {
        this.students = students;
    }

    /**
     * @return the accounts
     */
    public List<CustomerAccount> getAccounts() {
        return this.accounts;
    }

    /**
     * @param accounts the accounts to set
     */
    public void setAccounts(List<CustomerAccount> accounts) {
        this.accounts = accounts;
    }

    /**
     * @return the availableBenefits
     */
    public List<Benefit> getAvailableBenefits() {
        return this.availableBenefits;
    }

    /**
     * @param availableBenefits the availableBenefits to set
     */
    public void setAvailableBenefits(List<Benefit> availableBenefits) {
        this.availableBenefits = availableBenefits;
    }

    /**
     * @return the availableDiscounts
     */
    public List<Discount> getAvailableDiscounts() {
        return this.availableDiscounts;
    }

    /**
     * @param availableDiscounts the availableDiscounts to set
     */
    public void setAvailableDiscounts(List<Discount> availableDiscounts) {
        this.availableDiscounts = availableDiscounts;
    }

    /**
     * @return the debts
     */
    public List<Debt> getDebts() {
        return this.debts;
    }

    /**
     * @param debts the debts to set
     */
    public void setDebts(List<Debt> debts) {
        this.debts = debts;
    }

    /**
     * @return the amountToCreate
     */
    public Integer getAmountToCreate() {
        return this.amountToCreate;
    }

    /**
     * @param amountToCreate the amountToCreate to set
     */
    public void setAmountToCreate(Integer amountToCreate) {
        this.amountToCreate = amountToCreate;
    }

    /**
     * @return the selectedBenefits
     */
    public String getSelectedBenefits() {
        return this.selectedBenefits;
    }

    /**
     * @param selectedBenefits the selectedBenefits to set
     */
    public void setSelectedBenefits(String selectedBenefits) {
        this.selectedBenefits = selectedBenefits;
    }

    /**
     * @return the selectedDiscounts
     */
    public String getSelectedDiscounts() {
        return this.selectedDiscounts;
    }

    /**
     * @param selectedDiscounts the selectedDiscounts to set
     */
    public void setSelectedDiscounts(String selectedDiscounts) {
        this.selectedDiscounts = selectedDiscounts;
    }

    /**
     * @return the studentSurname
     */
    public String getStudentSurname() {
        return this.studentSurname;
    }

    /**
     * @param studentSurname the studentSurname to set
     */
    public void setStudentSurname(String studentSurname) {
        this.studentSurname = studentSurname;
    }

    /**
     * @return the discountValues
     */
    public String getDiscountValues() {
        return this.discountValues;
    }

    /**
     * @param discountValues the discountValues to set
     */
    public void setDiscountValues(String discountValues) {
        this.discountValues = discountValues;
    }

    /**
     * @return the discountPerc
     */
    public String getDiscountPerc() {
        return this.discountPerc;
    }

    /**
     * @param discountPerc the discountPerc to set
     */
    public void setDiscountPerc(String discountPerc) {
        this.discountPerc = discountPerc;
    }

    /**
     * @return the benefitValues
     */
    public String getBenefitValues() {
        return this.benefitValues;
    }

    /**
     * @param benefitValues the benefitValues to set
     */
    public void setBenefitValues(String benefitValues) {
        this.benefitValues = benefitValues;
    }

    /**
     * @return the benefitPerc
     */
    public String getBenefitPerc() {
        return this.benefitPerc;
    }

    /**
     * @param benefitPerc the benefitPerc to set
     */
    public void setBenefitPerc(String benefitPerc) {
        this.benefitPerc = benefitPerc;
    }

    /**
     * @return the debtTypeSelected
     */
    public String getDebtTypeSelected() {
        return this.debtTypeSelected;
    }

    /**
     * @param debtTypeSelected the debtTypeSelected to set
     */
    public void setDebtTypeSelected(String debtTypeSelected) {
        this.debtTypeSelected = debtTypeSelected;
    }

    /**
     * @return the debtTypeOptions
     */
    public List<LabelValueBean> getDebtTypeOptions() {
        return this.debtTypeOptions;
    }

    /**
     * @param debtTypeOptions the debtTypeOptions to set
     */
    public void setDebtTypeOptions(List<LabelValueBean> debtTypeOptions) {
        this.debtTypeOptions = debtTypeOptions;
    }

    

    /**
     * @return the debtStatusSelected
     */
    public String getDebtStatusSelected() {
        return this.debtStatusSelected;
    }

    /**
     * @param debtStatusSelected the debtStatusSelected to set
     */
    public void setDebtStatusSelected(String debtStatusSelected) {
        this.debtStatusSelected = debtStatusSelected;
    }

    /**
     * @return the debtStatusOptions
     */
    public List<LabelValueBean> getDebtStatusOptions() {
        return this.debtStatusOptions;
    }

    /**
     * @param debtStatusOptions the debtStatusOptions to set
     */
    public void setDebtStatusOptions(List<LabelValueBean> debtStatusOptions) {
        this.debtStatusOptions = debtStatusOptions;
    }

    /**
     * @return the reason
     */
    public String getReason() {
        return this.reason;
    }

    /**
     * @param reason the reason to set
     */
    public void setReason(String reason) {
        this.reason = reason;
    }

    /**
     * @return the courseSelected
     */
    public String getCourseSelected() {
        return this.courseSelected;
    }

    /**
     * @param courseSelected the courseSelected to set
     */
    public void setCourseSelected(String courseSelected) {
        this.courseSelected = courseSelected;
    }

    /**
     * @return the courseOptions
     */
    public List<LabelValueBean> getCourseOptions() {
        return this.courseOptions;
    }

    /**
     * @param courseOptions the courseOptions to set
     */
    public void setCourseOptions(List<LabelValueBean> courseOptions) {
        this.courseOptions = courseOptions;
    }

    /**
     * @return the customerId
     */
    public Long getCustomerId() {
        return this.customerId;
    }

    /**
     * @param customerId the customerId to set
     */
    public void setCustomerId(Long customerId) {
        this.customerId = customerId;
    }

    /**
     * @return the corporateName
     */
    public String getCorporateName() {
        return this.corporateName;
    }

    /**
     * @param corporateName the corporateName to set
     */
    public void setCorporateName(String corporateName) {
        this.corporateName = corporateName;
    }

	/**
	 * @return the filterStudents
	 */
	public Boolean getFilterStudents() {
		return filterStudents;
	}

	/**
	 * @param filterStudents the filterStudents to set
	 */
	public void setFilterStudents(Boolean filterStudents) {
		this.filterStudents = filterStudents;
	}

	public boolean isFilterStudentsOn() {
		if (this.filterStudents == true) {
			return true;
		}
		return false;
	}

	/**
	 * @return the debtStatusStr
	 */
	public String getDebtStatusStr() {
		return debtStatusStr;
	}

	/**
	 * @param debtStatusStr the debtStatusStr to set
	 */
	public void setDebtStatusStr(String debtStatusStr) {
		this.debtStatusStr = debtStatusStr;
	}
    
    
    
}
